﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Data;

namespace DbDoc.BusinessObjects
{
    [Serializable()]  
    public abstract class DbObject : BaseObject
    {
        private int _Id;

        public int Id
        {
            get { return _Id; }
            set { _Id = value; }
        }
        private string _Name;

        public string Name
        {
            get { return _Name; }
            set { _Name = value; }
        }
        private Comment _Comment;

        public Comment Comment
        {
            get { return _Comment; }
            set { _Comment = value; }
        }

        private bool _Deleted;

        public bool Deleted
        {
            get { return _Deleted; }
            set { _Deleted = value; }
        }

        private DbObject _Parent;

        public DbObject Parent
        {
            get { return _Parent; }
            set { _Parent = value; }
        }

        private string _Description;

        public string Description
        {
            get { return _Description; }
            set { _Description = value; }
        }

        public bool IsSystemObject { get; set; }
        public string SystemInfo { get; set; }
    
        private bool _DbType;
        public abstract DbType DbType{get ; }
       

        public DbObject(int id)
        {
            Id = id;
            _Comment = new Comment();
        }

        public DbObject()
        {
            _Comment = new Comment();
        }
        public DbObject(IDataReader reader)
        {
            _Comment = new Comment();
            this.Id = reader.GetInt32(reader.GetOrdinal("Id"));
            this.Deleted = reader.GetBoolean(reader.GetOrdinal("Deleted"));
            this.Name = reader.GetString(reader.GetOrdinal("Name"));
            this.Description = reader.GetString(reader.GetOrdinal("Description"));

            if (!reader.IsDBNull(reader.GetOrdinal("CommentId")))
                this.Comment.Id = reader.GetInt32(reader.GetOrdinal("CommentId"));
            if (!reader.IsDBNull(reader.GetOrdinal("Message")))
                this.Comment.Text = reader.GetString(reader.GetOrdinal("Message"));
            if (!reader.IsDBNull(reader.GetOrdinal("CreatedBy")))
                this.Comment.CreatedBy = reader.GetString(reader.GetOrdinal("CreatedBy"));
            if (!reader.IsDBNull(reader.GetOrdinal("CreatedOn")))
                this.Comment.CreatedOn = reader.GetDateTime(reader.GetOrdinal("CreatedOn"));
            if (!reader.IsDBNull(reader.GetOrdinal("ModifiedBy")))
                this.Comment.ModifiedBy = reader.GetString(reader.GetOrdinal("ModifiedBy"));
            if (!reader.IsDBNull(reader.GetOrdinal("ModifiedOn")))
                this.Comment.ModifiedOn = reader.GetDateTime(reader.GetOrdinal("ModifiedOn"));
            if (!reader.IsDBNull(reader.GetOrdinal("IsSystemObject")))
                this.IsSystemObject = reader.GetBoolean(reader.GetOrdinal("IsSystemObject"));
            if (!reader.IsDBNull(reader.GetOrdinal("SystemInfo")))
                this.SystemInfo = reader.GetString(reader.GetOrdinal("SystemInfo"));
        }

        public abstract IEnumerable<DbObject> Children
        { get; }
      
        public virtual void Save() { }       
    }
}
